package com.listAdapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bit.campusapp.R;
import com.bookmarket.BookItems;
import com.club.ClubAlllList;
import com.club.Club_BoardList;
import com.eatandenjoy.EatAndEnjoy_list;

/**
 * 
 * @author Hyeongrok
 * 
 */

public class MyListAdapter extends BaseAdapter {

	Context context;
	ArrayList<Object> items;
	LayoutInflater inflater;
	int layout;
	int type;				
	
	public MyListAdapter(Context context, int layout, int type,
			ArrayList<Object> items) {
		this.context = context;
		this.items = items;
		this.layout = layout;
		this.type = type;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int pos) {
		return items.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		ClubAllListViewHolder ch;
		CLubBoardViewHolder cb;
		BookMarket_ViewHolder bv;
		EatAndEnjoyViewHolder ene;
		
		switch (type) {
		case 0:
		case 1:
			if (convertView == null) {
				bv = new BookMarket_ViewHolder();
				convertView = inflater.inflate(layout, null);
				bv.iv = (ImageView) convertView.findViewById(R.id.book_img);
				bv.tv_title = (TextView) convertView.findViewById(R.id.book_title);
				bv.tv_writer = (TextView) convertView.findViewById(R.id.book_writer);
				bv.tv_date_write = (TextView) convertView.findViewById(R.id.book_date_write);
				bv.tv_readcount = (TextView) convertView.findViewById(R.id.book_readcount);
				convertView.setTag(bv);
			} else {
				bv = (BookMarket_ViewHolder) convertView.getTag();
			}
			bv.iv.setImageBitmap(((BookItems) items.get(pos)).getImg_path());
			bv.tv_title.setText(((BookItems) items.get(pos)).getTitle());
			bv.tv_writer.setText(((BookItems) items.get(pos)).getWriter());
			bv.tv_date_write.setText(((BookItems) items.get(pos)).getDate_write());
			bv.tv_readcount.setText(String.valueOf(((BookItems) items.get(pos)).getReadcount()));
			break;
		case 2:
		case 3:
			if(convertView == null){
				ene = new EatAndEnjoyViewHolder();
				convertView= inflater.inflate(layout, null);
				ene.EnEWtv = (TextView) convertView.findViewById(R.id.eatandrnoyj_writer);
				ene.EnEiv = (ImageView) convertView.findViewById(R.id.eatandrnoyj_img);
				ene.Enetv = (TextView) convertView.findViewById(R.id.eatandrnoyj_title);
				
				convertView.setTag(ene);
			}else{
				ene = (EatAndEnjoyViewHolder) convertView.getTag();
			}
			ene.EnEWtv.setText(((EatAndEnjoy_list) items.get(pos)).getEnEWtv());
			ene.EnEiv.setImageResource(((EatAndEnjoy_list) items.get(pos)).getEnEiv());
			ene.Enetv.setText(((EatAndEnjoy_list) items.get(pos)).getEnEtv());
			
			break;
			
		}
		
		return convertView;
	}

}
